/* Copyright (C) 2010 Luca Piccinelli
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/* 
 * File:   load.
 * Author: picci
 *
 * Created on August 2, 2011, 6:29 PM
 */

#include "pipeline/load.h"

#include <vector>

namespace NAMESPACE{

// ****** PipelineLoader implementation ****************************************     
    
PipelineLoader::PipelineLoader() : descr_builder(0), descr_consumer(0){}    
    
PipelineLoader& PipelineLoader::set_descr_builder(PipeStepDescrBuilder* builder){
    descr_builder = builder;
}

PipelineLoader& PipelineLoader::set_descr_consumer(PipeStepDescrConsumer* consumer){
    descr_consumer = consumer;
}

PipelineLoader& PipelineLoader::load() const{
    if(!descr_builder)  throw std::runtime_error("In PipelineLoader::load: No pipestep description builder set");
    if(!descr_consumer) throw std::runtime_error("In PipelineLoader::load: No pipestep description consumer set");
    
    std::vector<PipeStepDescriptor*> descriptors;
    descr_builder->build(descriptors);
    
    std::vector<PipeStepDescriptor*>::const_iterator descr_it     = descriptors.begin(),
                                                     end_descr_it = descriptors.end();
    for(; descr_it != end_descr_it; descr_it++){
        descr_consumer->consume(**descr_it);
    }
    
    for(descr_it = descriptors.begin(); descr_it != end_descr_it; descr_it++) delete *descr_it;
}

// -----------------------------------------------------------------------------

}
